home *** CD-ROM | disk | FTP | other *** search
/ Floppyshop 2 / Floppyshop - 2.zip / Floppyshop - 2.iso / art&graf.ix / art-0039 / source / dcdpalet.mod < prev    next >
Text File  |  1997-04-16  |  16KB  |  476 lines

  1. IMPLEMENTATION MODULE DCDPalette;
  2.  
  3.  
  4. (*--------------------------------------------------------------------*)
  5. (*                                                                    *)
  6. (*   This library module is reponsible for processing palette dialogs *)
  7. (*   for DegasConvert. This module will show the dialogue, return     *)
  8. (*   the input but will NOT clean up the screen. The calling program  *)
  9. (*   is reponsible for that.                                          *)
  10. (*                                                                    *)
  11. (*   Amendments:                                                      *)
  12. (*                                                                    *)
  13. (*                                August 1988     L.G.Miller          *)
  14. (*                                :- add pixel dialog                 *)
  15. (*                                                                    *)
  16. (*                                                                    *)
  17. (*                                August 1987     L.G.Miller          *)
  18. (*                                                                    *)
  19. (*                                                                    *)
  20. (*  25/ 8/89 LGM : Use new picture conversion routines.               *)
  21. (*                                                                    *)
  22. (*--------------------------------------------------------------------*)
  23.  
  24.  
  25. (*  IMPORT Trace; *)
  26.  
  27. FROM DCGlobal           IMPORT (* CONST *)
  28.                                LowRes,
  29.                                MedRes,
  30.                                HiRes,
  31.  
  32.                                DegasPicture,
  33.  
  34.                                PaletteEntry,
  35.                                PrintPalette,
  36.  
  37.                    BITSPERWORD;
  38.  
  39.  
  40. IMPORT DCPicCnv;
  41.  
  42.  
  43. FROM SYSTEM             IMPORT  ADDRESS, ADR;
  44.  
  45. FROM Strings            IMPORT String, Assign, Concat, Length;
  46.  
  47. FROM   GemObjects    IMPORT  TreePointer, GetObjectSpec, SelectObject,
  48.                 DeselectObject, GetTEDData, SetTEDData,
  49.                 GetState, SetState;
  50.  
  51. IMPORT Object;
  52.  
  53. IMPORT Forms;
  54. FROM Forms              IMPORT  DialAction;
  55.  
  56. FROM ManyWindow IMPORT
  57.  
  58. (* VAR  *) 
  59.   AESApplId,           (* AES handle for this application *)
  60.   VDIHandle,           (* VDI handle of current Virtual Workstation *)
  61.  
  62.   ShowMouse,
  63.   HideMouse;
  64.  
  65. FROM  Dcrsc    IMPORT
  66.   paletbox,  (* dialogue box for getting print bit patterns *)
  67.    prgb000,             pindex00,               ppat000,        
  68.    prgb001,             pindex01,               ppat001,        
  69.    prgb002,             pindex02,               ppat002,         
  70.    prgb003,             pindex03,               ppat003,         
  71.    prgb004,             pindex04,               ppat004,         
  72.    prgb005,             pindex05,               ppat005,         
  73.    prgb006,             pindex06,               ppat006,         
  74.    prgb007,             pindex07,               ppat007,         
  75.    prgb008,             pindex08,               ppat008,         
  76.    prgb009,             pindex09,               ppat009,        
  77.    prgb010,             pindex10,               ppat010,         
  78.    prgb011,             pindex11,               ppat011,         
  79.    prgb012,             pindex12,               ppat012,        
  80.    prgb013,             pindex13,               ppat013,           
  81.    prgb014,             pindex14,               ppat014,         
  82.    prgb015,             pindex15,               ppat015,         
  83.  
  84.    ppalok,           (* ok box for palette *)
  85.    ppalcan,          (* cancel box for palette *)
  86.  
  87. (*----------------------------------------------------------------------*)
  88. (* constants for the pixel enquiry/update dialog                        *)
  89. (*----------------------------------------------------------------------*)
  90.  
  91.    dpixel,        (* dialog tree *)
  92.    dpixrgb,        
  93.    dpixindx,      
  94.    dpixpbp,       
  95.  
  96.    dpixok,        
  97.    dpixcan;       
  98.  
  99. (* -------------------- End of IMPORTS ----------------------- *)
  100.  
  101.  
  102.  
  103. (*----------------------------------------------------------------------*)
  104. (*                  G L O B A L   T Y P E S                             *)
  105. (*----------------------------------------------------------------------*)
  106.  
  107. TYPE
  108.  
  109.  
  110.   StringPtr = POINTER TO String; (* null terminated *)
  111.  
  112.   DialogLine = (* object numbers *)
  113.     RECORD
  114.       rgbcomp,
  115.       lineno,
  116.       pattern  : INTEGER;
  117.     END;
  118.  
  119.  
  120. (*----------------------------------------------------------------------*)
  121. (*   low-level dialog line routine to clear an entry and protect it     *)
  122. (*----------------------------------------------------------------------*)
  123. PROCEDURE ClearPrintDialogLine (  VAR dline : DialogLine;
  124.                                       dtreei : INTEGER );
  125.   VAR sptr   : StringPtr;
  126.   BEGIN
  127.     sptr   := GetObjectSpec( dtreei, dline.rgbcomp );
  128.     Assign('   ', sptr^);
  129.  
  130.     sptr   := GetObjectSpec( dtreei, dline.lineno );
  131.     Assign('  ', sptr^);
  132.  
  133.     SetTEDData( dtreei, dline.pattern, '    ' );
  134.  
  135.   END ClearPrintDialogLine;
  136.  
  137.  
  138. (*----------------------------------------------------------------------*)
  139. (*   low-level dialog line routine to load an entry                     *)
  140. (*----------------------------------------------------------------------*)
  141. PROCEDURE LoadPrintDialogLine (  VAR dline  : DialogLine;
  142.                                      pentry : PaletteEntry;
  143.                                      dtreei  : INTEGER;
  144.                                      res    : CARDINAL );
  145.   VAR sptr       : StringPtr;
  146.       tedptr     : POINTER TO Object.TEDINFO;
  147.       tstr, nstr : String;
  148.       i          : INTEGER;
  149.       flags      : BITSET;
  150.   BEGIN
  151.     Assign( '000',tstr);
  152.     tstr[0] := CHR( ORD('0') + CARDINAL(pentry.RedComponent)   );
  153.     tstr[1] := CHR( ORD('0') + CARDINAL(pentry.GreenComponent) );
  154.     tstr[2] := CHR( ORD('0') + CARDINAL(pentry.BlueComponent)  );
  155.     sptr    := GetObjectSpec( dtreei, dline.rgbcomp );
  156.     Assign(tstr, sptr^);
  157.  
  158. (*    simple way of converting a number to a two digit string      *)
  159.     Assign('00010203040506070809101112131415', nstr);
  160.     Assign('00', tstr);
  161.     tstr[0] := nstr[ (pentry.ColourIndex * 2) ];
  162.     tstr[1] := nstr[ (pentry.ColourIndex * 2) + 1 ];
  163.     sptr    := GetObjectSpec( dtreei, dline.lineno );
  164.     Assign(tstr, sptr^);
  165.  
  166. (*----------------------------------------------------------------------*)
  167. (* The pattern string is a TEDinfo structure and will need dereferencing*)
  168. (*----------------------------------------------------------------------*)
  169.     tedptr := GetObjectSpec( dtreei, dline.pattern );
  170.     SetState( dtreei, dline.pattern, Object.ObjectStates{} );
  171.     IF res = MedRes THEN
  172.        Assign('00', tstr);
  173.        IF 0 IN pentry.PrintBitPattern THEN tstr[1] := '1' END;
  174.        IF 1 IN pentry.PrintBitPattern THEN tstr[0] := '1' END;
  175.        sptr := tedptr^.te_ptext;
  176.        Assign(tstr, sptr^);
  177.        sptr := tedptr^.te_ptmplt;
  178.        Assign('__',sptr^);
  179.        sptr := tedptr^.te_pvalid;
  180.        Assign('99',sptr^);
  181.        tedptr^.te_txtlen := 3;
  182.        tedptr^.te_tmplen := 3;
  183.  
  184.     ELSE
  185.        Assign('0000', tstr);
  186.        IF 0 IN pentry.PrintBitPattern THEN tstr[3] := '1' END;
  187.        IF 1 IN pentry.PrintBitPattern THEN tstr[2] := '1' END;
  188.        IF 2 IN pentry.PrintBitPattern THEN tstr[1] := '1' END;
  189.        IF 3 IN pentry.PrintBitPattern THEN tstr[0] := '1' END;
  190.        sptr := tedptr^.te_ptext;
  191.        Assign(tstr, sptr^);
  192.        sptr := tedptr^.te_ptmplt;
  193.        Assign('____', sptr^);
  194.        sptr := tedptr^.te_pvalid;
  195.        Assign('9999', sptr^);
  196.        tedptr^.te_txtlen := 5;
  197.        tedptr^.te_tmplen := 5;
  198.     END; (* if *)
  199.  
  200.  END LoadPrintDialogLine;
  201.  
  202.  
  203. (*----------------------------------------------------------------------*)
  204. (* return the print pattern from one line of the dialog ( in pentry )   *)
  205. (*----------------------------------------------------------------------*)
  206. PROCEDURE GetDialogPrintPattern( VAR dline  : DialogLine;
  207.                                  VAR pentry : PaletteEntry;
  208.                                      dtreei  : INTEGER;
  209.                                      res    : CARDINAL );
  210.   VAR sptr       : StringPtr;
  211.       tedptr     : POINTER TO Object.TEDINFO;
  212.       tstr, nstr : String;
  213.       i, lim     : INTEGER;
  214.   BEGIN
  215.     tedptr := GetObjectSpec( dtreei, dline.pattern );
  216.     sptr := tedptr^.te_ptext;
  217.     Assign(sptr^, tstr);
  218.     Concat(tstr,'0000',tstr);
  219.     IF res = MedRes THEN
  220.        lim := 1;
  221.     ELSE
  222.        lim := 3;
  223.     END;
  224.  
  225.     FOR i := 0 TO lim DO
  226.       IF tstr[i] = '0' THEN
  227.          EXCL(pentry.PrintBitPattern, (lim-i));
  228.       ELSE
  229.          INCL(pentry.PrintBitPattern, (lim-i));
  230.       END; (* if *)
  231.     END; (* for i *)
  232.   END GetDialogPrintPattern;
  233.  
  234.  
  235. (*----------------------------------------------------------------------*)
  236. (*   Clear Dialog Tree of current values and protect all entries        *)
  237. (*----------------------------------------------------------------------*)
  238. PROCEDURE ResetDialog ( VAR dlines   : ARRAY OF DialogLine;
  239.                         VAR pentries : PrintPalette;
  240.                             dtreei    : INTEGER;
  241.                             res      : INTEGER );
  242.   VAR i, lim : INTEGER;
  243.   BEGIN
  244.     FOR i := 0 TO SHORT(HIGH(dlines)) DO
  245.       ClearPrintDialogLine( dlines[i], dtreei);
  246.     END; (* for *)
  247.  
  248.     lim := SHORT(HIGH(dlines));
  249.     IF res = MedRes THEN
  250.       lim := 3;
  251.     END;
  252.  
  253.     FOR i := 0 TO lim DO
  254.       LoadPrintDialogLine( dlines[i], pentries[i], dtreei, res );
  255.     END; (* for *)
  256.   END ResetDialog;
  257.  
  258.  
  259.  
  260. (*----------------------------------------------------------------------*)
  261. (* Load array with object numbers of the components of a line of dialog *)
  262. (*----------------------------------------------------------------------*)
  263. PROCEDURE InitArray( VAR objectsarray : ARRAY OF DialogLine );
  264.   BEGIN
  265.  
  266.   WITH objectsarray[0] DO
  267.       rgbcomp :=  prgb000;
  268.       lineno  :=  pindex00;
  269.       pattern :=  ppat000;
  270.   END;
  271.  
  272.   WITH objectsarray[1] DO
  273.       rgbcomp :=  prgb001;
  274.       lineno  :=  pindex01;
  275.       pattern :=  ppat001;
  276.   END;
  277.  
  278.   WITH objectsarray[2] DO
  279.       rgbcomp :=  prgb002;
  280.       lineno  :=  pindex02;
  281.       pattern :=  ppat002;
  282.   END;
  283.  
  284.   WITH objectsarray[3] DO
  285.       rgbcomp :=  prgb003;
  286.       lineno  :=  pindex03;
  287.       pattern :=  ppat003;
  288.   END;
  289.  
  290.   WITH objectsarray[4] DO
  291.       rgbcomp :=  prgb004;
  292.       lineno  :=  pindex04;
  293.       pattern :=  ppat004;
  294.   END;
  295.  
  296.   WITH objectsarray[5] DO
  297.       rgbcomp :=  prgb005;
  298.       lineno  :=  pindex05;
  299.       pattern :=  ppat005;
  300.   END;
  301.  
  302.   WITH objectsarray[6] DO
  303.       rgbcomp :=  prgb006;
  304.       lineno  :=  pindex06;
  305.       pattern :=  ppat006;
  306.   END;
  307.  
  308.   WITH objectsarray[7] DO
  309.       rgbcomp :=  prgb007;
  310.       lineno  :=  pindex07;
  311.       pattern :=  ppat007;
  312.   END;
  313.  
  314.   WITH objectsarray[8] DO
  315.       rgbcomp :=  prgb008;
  316.       lineno  :=  pindex08;
  317.       pattern :=  ppat008;
  318.   END;
  319.  
  320.   WITH objectsarray[9] DO
  321.       rgbcomp :=  prgb009;
  322.       lineno  :=  pindex09;
  323.       pattern :=  ppat009;
  324.   END;
  325.  
  326.   WITH objectsarray[10] DO
  327.       rgbcomp :=  prgb010;
  328.       lineno  :=  pindex10;
  329.       pattern :=  ppat010;
  330.   END;
  331.  
  332.   WITH objectsarray[11] DO
  333.       rgbcomp :=  prgb011;
  334.       lineno  :=  pindex11;
  335.       pattern :=  ppat011;
  336.   END;
  337.  
  338.   WITH objectsarray[12] DO
  339.       rgbcomp :=  prgb012;
  340.       lineno  :=  pindex12;
  341.       pattern :=  ppat012;
  342.   END;
  343.  
  344.   WITH objectsarray[13] DO
  345.       rgbcomp :=  prgb013;
  346.       lineno  :=  pindex13;
  347.       pattern :=  ppat013;
  348.   END;
  349.  
  350.   WITH objectsarray[14] DO
  351.       rgbcomp :=  prgb014;
  352.       lineno  :=  pindex14;
  353.       pattern :=  ppat014;
  354.   END;
  355.  
  356.   WITH objectsarray[15] DO
  357.       rgbcomp :=  prgb015;
  358.       lineno  :=  pindex15;
  359.       pattern :=  ppat015;
  360.   END;
  361.  
  362.   END InitArray;
  363.  
  364. (*----------------------------------------------------------------------*)
  365. (*    P I X E L      D I A L O G                                        *)
  366. (*----------------------------------------------------------------------*)
  367.  
  368. (*----------------------------------------------------------------------*)
  369. (* use the above print dialog routines for loading/clearing the         *)
  370. (* dpixel dialog.                                                       *)
  371. (* Note: It is no coincidence that the DPIXEL resource structure is the *)
  372. (*       same as a DialogPrintLine Entry                                *)
  373. (*----------------------------------------------------------------------*)
  374.  
  375.  
  376. (*----------------------------------------------------------------------*)
  377. (*  Run dialogue to get print patterns from the user                    *)
  378. (*----------------------------------------------------------------------*)
  379. PROCEDURE DoPaletteDialog ( VAR    pp   : PrintPalette;
  380.                                    res  : CARDINAL ) : BOOLEAN;
  381.   VAR i, entries : INTEGER;
  382.       dlines     : ARRAY [ 0 .. 15 ] OF DialogLine;
  383.  
  384.       dTree      : ADDRESS ;
  385.       x, y, w, h, dumc : CARDINAL ;
  386.       result     : INTEGER;
  387.   BEGIN
  388.     InitArray( dlines );
  389.     IF res = LowRes THEN
  390.        DCPicCnv.SortByColour( pp, 16 );
  391.     ELSE
  392.        DCPicCnv.SortByColour( pp,  4 );
  393.     END; 
  394.     ResetDialog( dlines, pp, paletbox, INTEGER(res) );
  395.  
  396.     DeselectObject(paletbox, ppalok) ;
  397.     DeselectObject(paletbox, ppalcan) ;
  398.     dTree := TreePointer( paletbox );
  399.     Forms.form_center(dTree, x, y, w, h) ;
  400.     dumc := Forms.form_dial(ReserveSpace, 0, 0, 0, 0, x, y, w, h) ;
  401.     dumc := Forms.form_dial(ExpandBox, 0, 0, 0, 0, x, y, w, h) ;
  402.     dumc := Object.objc_draw(dTree, 0, 10, x, y, w, h) ;
  403.     result := Forms.form_do(dTree, dlines[0].pattern) ;
  404.     dumc := Forms.form_dial(ShrinkBox, 0, 0, 0, 0, x, y, w, h) ;
  405.     dumc := Forms.form_dial(FreeSpace, 0, 0, 0, 0, x, y, w, h) ;
  406.  
  407.     IF result = ppalok THEN
  408.        FOR i := 0 TO HIGH(pp) DO
  409.          GetDialogPrintPattern( dlines[i], pp[i], paletbox, INTEGER(res) );
  410.        END; (* for i *)
  411.     END; (* if *)
  412.     DCPicCnv.SortByIndex( pp, 16 );
  413.     RETURN ( result = ppalok );
  414.   END DoPaletteDialog;
  415.  
  416.  
  417. (*----------------------------------------------------------------------*)
  418. (*  Run pixel dialog.                                                   *)
  419. (*----------------------------------------------------------------------*)
  420. PROCEDURE DoPixelDialog   ( VAR  picture : DegasPicture;
  421.                                  mousex, mousey,
  422.                                  screenres  : CARDINAL;
  423.                             VAR  pp   : PrintPalette ) ;
  424.   VAR entry      : INTEGER;
  425.       dline      : DialogLine;
  426.       pentry     : PaletteEntry;
  427.  
  428.       dTree      : ADDRESS ;
  429.       x, y, w, h, dumc : CARDINAL ;
  430.       result     : INTEGER;
  431.   BEGIN
  432.     WITH dline DO
  433.       rgbcomp :=  dpixrgb;
  434.       lineno  :=  dpixindx;
  435.       pattern :=  dpixpbp;
  436.     END;
  437.  
  438.         (* convert input mouse co-ords to med-res co-ords *)
  439.     IF screenres = HiRes THEN
  440.        mousey := mousey DIV 2;
  441.     END;
  442.  
  443.  
  444.     IF ( picture.resolution = LowRes )  THEN
  445.        mousex := mousex DIV 2;
  446.        entry := DCPicCnv.QueryXYLowResPixelIndex( mousex, mousey, picture);
  447.     ELSE
  448.        entry := DCPicCnv.QueryXYMedResPixelIndex( mousex, mousey, picture);
  449.     END;
  450.  
  451.     dTree := TreePointer( dpixel );
  452.  
  453.     ClearPrintDialogLine( dline, dpixel);
  454.  
  455.     LoadPrintDialogLine( dline, pp[entry], dpixel, picture.resolution );
  456.  
  457.  
  458.     DeselectObject(dpixel, dpixok);
  459.     DeselectObject(dpixel, dpixcan);
  460.     Forms.form_center(dTree, x, y, w, h) ;
  461.     dumc := Forms.form_dial(ReserveSpace, 0, 0, 0, 0, x, y, w, h) ;
  462.     dumc := Forms.form_dial(ExpandBox, 0, 0, 0, 0, x, y, w, h) ;
  463.     dumc := Object.objc_draw(dTree, 0, 10, x, y, w, h) ;
  464.     result := Forms.form_do(dTree, dline.pattern) ;
  465.     dumc := Forms.form_dial(ShrinkBox, 0, 0, 0, 0, x, y, w, h) ;
  466.     dumc := Forms.form_dial(FreeSpace, 0, 0, 0, 0, x, y, w, h) ;
  467.  
  468.     IF result = dpixok THEN
  469.          GetDialogPrintPattern( dline, pp[entry], dpixel,
  470.                                 picture.resolution );
  471.     END; (* if *)
  472.   END DoPixelDialog;
  473.  
  474. END DCDPalette.
  475.  
  476.